#include "StdAfx.h"

#include "Point.h"

Point::Point(double x, double y, double z) : X(x), Y(y), Z(z) //didn't use set because of cost of function call
{}

Point::Point(const Point& p) : X(p.X), Y(p.Y), Z(p.Z)
{}


void Point::Set(double x, double y, double z)
{
	X = x;
	Y = y;
	Z = z;
}

void Point::Set(const Point& point)
{
	*this = point;
}

Point Point::operator+ (const Point& point) const
{
	return Point(X + point.X, Y + point.Y, Z + point.Z);
}

Point Point::operator- (const Point& point) const
{
	return Point(X - point.X, Y - point.Y, Z - point.Z);
}

Point Point::operator- () const
{
	return Point(-X, -Y, -Z);
}

Point Point::operator* (double scalar) const
{
	return Point(X * scalar, Y * scalar, Z * scalar);
}

Point Point::operator/ (double scalar) const
{
	if (scalar != 0)
	{
		scalar = 1 / scalar;	
		return Point (X * scalar, Y * scalar, Z * scalar);
	}
	else
		return Infinity();
}

double Point::ScalarProduct(const Point& point) const
{
	return X * point.X + Y * point.Y + Z * point.Z;
}

void Point::Normalize()
{
	double length = sqrt(X * X + Y * Y + Z * Z);
	X /= length;
	Y /= length;
	Z /= length;
}

void Point::operator+=(const Point& p)
{
	X += p.X;
	Y += p.Y;
	Z += p.Z;
}

void Point::operator-=(const Point& p)
{
	X -= p.X;
	Y -= p.Y;
	Z -= p.Z;
}

void Point::operator*=(double scalar)
{
	X *= scalar;
	Y *= scalar;
	Z *= scalar;
}

double Point::Length()
{
	return sqrt(X*X + Y*Y + Z*Z);
}

double Point::SquaredLength()
{
	return X*X + Y*Y + Z*Z;
}

void Point::TransMultiplication(const Point& point)
{
	X *= point.X;
	Y *= point.Y;
	Z *= point.Z;
}

Point Point::Infinity()
{
	return Point(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity());
}